export interface Player {
  profile: {
    account_id: number
    personaname: string
    name?: string
    avatar: string
    avatarmedium: string
    avatarfull: string
    profileurl: string
    last_login?: string
    loccountrycode?: string
  }
  rank_tier?: number
  leaderboard_rank?: number
}

export interface Match {
  match_id: number
  player_slot: number
  radiant_win: boolean
  duration: number
  game_mode: number
  lobby_type: number
  hero_id: number
  start_time: number
  version?: number
  kills: number
  deaths: number
  assists: number
  skill?: number
  xp_per_min: number
  gold_per_min: number
  hero_damage: number
  tower_damage: number
  hero_healing: number
  last_hits: number
  denies: number
  lane_role?: number
  is_roaming?: boolean
  cluster?: number
  leaver_status: number
  party_size?: number
}

export interface Hero {
  id: number
  name: string
  localized_name: string
  primary_attr: string
  attack_type: string
  roles: string[]
  img: string
  icon: string
}

export interface PlayerStats {
  tracked_until: string
  solo_competitive_rank: number
  competitive_rank: number
  rank_tier: number
  leaderboard_rank: number
  mmr_estimate: {
    estimate: number
  }
}

export interface MatchDetail {
  match_id: number
  barracks_status_dire: number
  barracks_status_radiant: number
  cluster: number
  dire_score: number
  duration: number
  engine: number
  first_blood_time: number
  game_mode: number
  human_players: number
  leagueid: number
  lobby_type: number
  match_seq_num: number
  negative_votes: number
  positive_votes: number
  radiant_gold_adv: number[]
  radiant_score: number
  radiant_win: boolean
  radiant_xp_adv: number[]
  start_time: number
  tower_status_dire: number
  tower_status_radiant: number
  version: number
  replay_salt: number
  series_id: number
  series_type: number
  skill: number
  patch: number
  region: number
  players: MatchPlayer[]
  picks_bans?: PickBan[]
  chat?: ChatMessage[]
  objectives?: any[]
  teamfights?: any[]
  radiant_team?: Team
  dire_team?: Team
  league?: League
}

export interface MatchPlayer {
  match_id: number
  player_slot: number
  ability_upgrades_arr: number[]
  account_id: number
  assists: number
  backpack_0: number
  backpack_1: number
  backpack_2: number
  camps_stacked: number
  creeps_stacked: number
  deaths: number
  denies: number
  gold: number
  gold_per_min: number
  gold_spent: number
  hero_damage: number
  hero_healing: number
  hero_id: number
  item_0: number
  item_1: number
  item_2: number
  item_3: number
  item_4: number
  item_5: number
  kills: number
  last_hits: number
  leaver_status: number
  level: number
  obs_placed: number
  sen_placed: number
  stuns: number
  tower_damage: number
  xp_per_min: number
  personaname?: string
  name?: string
  radiant_win: boolean
  start_time: number
  duration: number
  cluster: number
  lobby_type: number
  game_mode: number
  patch: number
  region: number
  isRadiant: boolean
  win: number
  lose: number
  total_gold: number
  total_xp: number
  kills_per_min: number
  kda: number
  abandons: number
  neutral_kills: number
  tower_kills: number
  courier_kills: number
  lane_kills: number
  hero_kills: number
  observer_kills: number
  sentry_kills: number
  roshan_kills: number
  necronomicon_kills: number
  ancient_kills: number
  buyback_count: number
  observer_uses: number
  sentry_uses: number
  lane_efficiency: number
  lane_efficiency_pct: number
  lane: number
  lane_role: number
  is_roaming: boolean
  actions_per_min: number
  life_state_dead: number
  rank_tier: number
}

export interface PickBan {
  is_pick: boolean
  hero_id: number
  team: number
  order: number
}

export interface ChatMessage {
  time: number
  unit: string
  key: string
  slot: number
  player_slot: number
}

export interface Ward {
  time: number
  type: number
  positionX: number
  positionY: number
}

export interface Team {
  team_id: number
  name: string
  tag: string
  logo_url: string | null
}

export interface League {
  leagueid: number
  ticket: string
  banner: string
  tier: string
  name: string
}

// 联赛搜索结果接口
export interface LeagueSearchResult {
  leagueid: number
  name: string
  tier: string
  banner?: string
  start_time?: number
  end_time?: number
  prize_pool?: number
  region?: string
}

// 联赛详细信息接口
export interface LeagueDetail {
  leagueid: number
  name: string
  tier: string
  banner?: string
  start_time?: number
  end_time?: number
  prize_pool?: number
  region?: string
  description?: string
  organizer?: string
  teams?: Team[]
  matches?: LeagueMatch[]
  
  // STRATZ API 特有字段
  url?: string
  venue?: string
  location?: string
  country?: string
  stats?: {
    matchCount?: number
    playerCount?: number
    teamCount?: number
  }
  nodeGroups?: Array<{
    id: number
    name: string
    description?: string
  }>
  liveMatches?: Array<{
    matchId: number
    createdDateTime: string
  }>
  streams?: Array<{
    name: string
    languageId?: number
  }>
  
  // 混合API策略新增字段
  timeSource?: string
}

// 联赛比赛接口
export interface LeagueMatch {
  match_id: number
  league_id: number
  start_time: number
  duration?: number
  radiant_team?: Team
  dire_team?: Team
  radiant_win?: boolean
  radiant_score?: number
  dire_score?: number
  game_mode?: number
  lobby_type?: number
  series_id?: number
  series_type?: number
}

// 新算法指标权重配置
export interface MetricWeights {
  hero_damage_per_min: number  // 英雄伤害/分钟 (HDPM)
  xpm: number                  // 经验/分钟 (XPM)
  gpm: number                  // 金钱/分钟 (GPM)
  vision_wards_per_min: number // 真假眼/分钟 (VWPM)
  crowd_control_per_min: number // 控制时间/分钟 (CCPM)
  healing_per_min: number      // 治疗/分钟 (HEPM)
  kill_participation: number   // 参战率 (KP%)
  deaths_per_min_penalty: number // 死亡/分钟惩罚系数
}

// 单场比赛的详细数据
export interface MatchPerformanceData {
  match_id: number
  duration: number // 比赛时长（秒）
  win: boolean
  
  // 原始指标数据
  kills: number
  deaths: number
  assists: number
  hero_damage: number
  xpm: number
  gpm: number
  observer_wards_placed: number
  sentry_wards_placed: number
  stuns: number // 控制时间（秒）
  hero_healing: number
  first_blood_claimed: boolean
  first_blood_given: boolean
  
  // 计算得出的指标
  hero_damage_per_min: number
  vision_wards_per_min: number
  crowd_control_per_min: number
  healing_per_min: number
  kill_participation: number // (kills + assists) / team_kills
  deaths_per_min: number
  
  // 该场比赛的Raw Score
  raw_score: number
  
  // 团队信息
  team_id?: number
  team_name?: string
  opponent_team_id?: number
  opponent_team_name?: string
}

// 团队Elo评分数据
export interface TeamEloData {
  team_id: number
  team_name: string
  elo_rating: number
  matches_played: number
  wins: number
  losses: number
}

// 玩家表现排名相关类型
export interface PlayerPerformanceStats {
  account_id: number
  personaname: string
  avatar?: string
  
  // 基础统计
  matches_played: number
  wins: number
  losses: number
  win_rate: number
  
  // KDA统计
  total_kills: number
  total_deaths: number
  total_assists: number
  total_last_hits: number
  total_denies: number
  total_gpm: number
  total_xpm: number
  total_hero_damage: number
  total_tower_damage: number
  total_hero_healing: number
  avg_kills: number
  avg_deaths: number
  avg_assists: number
  avg_kda: number
  
  // 经济效率
  avg_gpm: number
  avg_xpm: number
  avg_last_hits: number
  avg_denies: number
  
  // 伤害和治疗
  avg_hero_damage: number
  avg_tower_damage: number
  avg_hero_healing: number
  
  // 新算法相关字段
  match_performances?: MatchPerformanceData[] // 所有比赛的详细表现数据
  raw_score: number // 个人基础分 (Raw Score)
  team_multiplier: number // 团队加成系数 (Team Multiplier)
  final_score: number // 最终评分 (Raw Score * Team Multiplier)
  
  // 新增平均指标
  avg_hero_damage_per_min: number
  avg_vision_wards_per_min: number
  avg_crowd_control_per_min: number
  avg_healing_per_min: number
  avg_kill_participation: number
  avg_deaths_per_min: number
  
  // 旧算法兼容字段
  primary_role?: number // 主要位置 (1-5号位)
  role_distribution?: { [role: number]: number } // 各位置比赛场数分布
  las_score?: number // LAS评分 (0-100)
  
  // 综合评分（保持向后兼容）
  performance_score: number
  
  // 排名
  rank: number
}

export interface LeaguePlayerRanking {
  league_id: number
  league_name: string
  total_players: number
  players: PlayerPerformanceStats[]
  last_updated: number
}

// 视野大师排行榜数据结构
export interface VisionMasterStats {
  account_id: number
  personaname: string
  avatar?: string
  matches_played: number
  avg_wards_per_match: number
  max_wards_single_match: number
  win_rate: number
  total_wins: number
  total_losses: number
}

export interface VisionMasterRanking {
  league_id: number
  league_name: string
  total_players: number
  players: VisionMasterStats[]
  last_updated: number
}

// 杀戮机器排行榜数据结构
export interface KillingMachineStats {
  account_id: number
  personaname: string
  avatar?: string
  matches_played: number
  avg_kills_per_match: number
  max_kills_single_match: number
  win_rate: number
  total_wins: number
  total_losses: number
}

export interface KillingMachineRanking {
  league_id: number
  league_name: string
  total_players: number
  players: KillingMachineStats[]
  last_updated: number
}